trigger caseLegacyUpdateTrigger on Case (before insert) {
/*
    Id rectypeId;
    Id defaultOwnerId;
    Set<string> customerIds = new Set<string>();
    Set<string> ownerEmailIds = new Set<string>();
    
    //get the default owner for case  
    for(List<User> userList:[Select u.Id  From User u  where attuid__C = 'jb2391'])
    {       
               if(userList.size()>0)
                 defaultOwnerId= userList[0].Id;
    }
        
    //get the record type id for this case 
    for(List<RecordType> rtList:[Select Id From RecordType r where SobjectType = 'Case' and Name = 'White Space - Local Advertiser'])
    {
              if(rtList.size()>0)
                  rectypeId= rtList[0].Id;      
    }
    // store all AF customer id in this batch      
    for (Case cs : Trigger.new){
            //work only with legace case
            if(cs.Legacy_Case__c)
            {       
                 if(cs.Web_CMR_AFCustomerID__c != null)
                      customerIds.add(cs.Web_CMR_AFCustomerID__c);
                      
                 if(cs.AF_Contact__c != null)
                       ownerEmailIds.add(cs.AF_Contact__c);
                      
            }
        
    }
        
        //customer lookup
        Map<string,Id> accountMap = new Map<string,Id>(); 
        for(List<Account> accList:[Select AFrontier_CustomerID__c,Id From Account a where a.AFrontier_CustomerID__c in :customerIds ])
        {
            for(Account account:accList)
            {
               accountMap.put(account.AFrontier_CustomerID__c, account.Id); 
            }
            
        }
                
         //owner lookup
        Map<string,Id> ownerMap = new Map<string,Id>(); 
        for(List<User> ownerList:[Select Email,Id From User u where u.Email in :ownerEmailIds ])
        {
            for(User owner:ownerList)
            {
               ownerMap.put(owner.Email, owner.Id); 
            }
            
        }
        
        //update the case in this batch with lookup values   
        for (Case cs : Trigger.new){                
        //only legacy cases
        if(cs.Legacy_Case__c )
        {
            if(accountMap.containsKey(cs.Web_CMR_AFCustomerID__c))   
             {      
               cs.AccountId = accountMap.get(cs.Web_CMR_AFCustomerID__c);
               System.debug('>>>>>Account found: '+ cs.Id + ':'+ cs.Web_CMR_AFCustomerID__c + ':'+  cs.AccountId);
            }
            else
            {
                 System.debug('>>>>>Account not found: '+ cs.Id + ':'+  cs.Web_CMR_AFCustomerID__c + ':'+  cs.AccountId);
            }
            
            //lookup for owner in map using email address
            if(ownerMap.containsKey(cs.AF_Contact__c))
             {      
               cs.OwnerId = ownerMap.get(cs.AF_Contact__c);
               System.debug('>>>>>Owner found using Email: '+ cs.AF_Contact__c + ':'+  cs.OwnerId);
            }
            else
            {
                 System.debug('>>>>>Owner not found, using default owner : ' + cs.AF_Contact__c + ':'+  cs.OwnerId + ':' + defaultOwnerId);
                 //if owner not found ,assign default owner
                 if(defaultOwnerId != null )
                     cs.OwnerId= defaultOwnerId;
            }
            cs.RecordTypeId = rectypeId;
            cs.AFrontier_Last_Sync__c = DateTime.now();
        }
    } 
  */
  }